<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta content="telephone=no" name="format-detection" />
	<meta name="Description" content=""/>
	<meta name="Keywords" content=""/>
	<link href="favicon.ico" mce_href="favicon.ico" rel="bookmark" type="image/x-icon" />
	<link href="favicon.ico" mce_href="favicon.ico" rel="icon" type="image/x-icon" />
	<link href="favicon.ico" mce_href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
	<title>盖网魔盒</title>
	<link rel="stylesheet" href="css/reset.css">
	<link rel="stylesheet" href="css/styles.css">
	<script src="js/jquery-2.2.2.min.js"></script>
	<script src="js/jquery.flexslider-min.js"></script>
	<script src="js/cryptico.js"></script>
	<script src="js/jsencrypt.js"></script>
	<script src="js/common.js"></script>
	<script>
		$(function(){
			if(window.name=="gwmhLogined"){
				$("#authentication").attr("href","hasLogined.html");
			}

			$(".get-code").click(function(){
				var phoneReg=/^1[3458]\d{9}$/;
				if(!$("#phone").val()||!phoneReg.test($("#phone").val())){
					$("#phone-alert").show();
				}else{
					$("#get-code").show();					
				}				
			})				
			$(".tooltip-box .close").click(function(){
				$(this).parent().parent().hide();
			})
			$(".get-code-btn").click(function(){
				$("#get-code").hide();
			})
		})
	</script>		
</head>
<body>
	<header class="header">
		<a href="javascript:history.go(-1)" class="reback"></a>
	</header>
	<section class="container">
		<div class="ca-wrap">
			<div class="logo"></div>
			<div id="register-form">
				<div class="form-row">
					<input type="text" name="phoneNum" id="phone" class="form-input" placeholder="手机号" required>
				</div>
				<div class="form-row">
					<input type="text" name="verifyCode" class="form-input code-input" placeholder="验证码" required>
					<button type="button" href="#" class="get-code">获取验证码</button>
				</div>
				<div class="form-row">
					<input type="password" name="password" class="form-input" placeholder="密码" required>
				</div>
				<div class="form-row">
					<input type="password" name="confirmPassword" class="form-input" placeholder="确认密码" required>
					<p class="error-tip hide">两次输入的密码不一致</p>
				</div>
				<div class="operation">
					<input type="submit" class="submit-btn" value="注 册" onclick="xmlsubmit()">					
				</div>
			</div>
			<!--验证码发送弹窗-->
			<div id="get-code" class="mask hide">
				<div class="tooltip-box alert-box">
					<i class="close"></i>
		            <div class="message">语音验证码只支持中国地区（不含港澳台）的号码接收，为保证您能正常接收到语音验证码，请关闭陌生来电拦截和保证电话畅通。</div>
		            <input type="button" value="短信发送" class="get-code-btn" onclick="xmlverify(1)" />
		            <input type="button" value="语音发送" class="get-code-btn" onclick="xmlverify(2)" />
		        </div>
			</div>	
			<!--手机号码未填写或格式错误提示-->
			<div id="phone-alert" class="mask hide">
				<div class="tooltip-box">
					<i class="close"></i>
					<p>请输入正确的手机号码！</p>
				</div>
			</div>	
			<!--两次密码不一致提示-->
			<div id="pw-uniformity" class="mask hide">
				<div class="tooltip-box">
					<i class="close"></i>
					<p>密码输入不一致，请重新输入！</p>
				</div>
			</div>					
		</div>
	</section>
	<footer class="footer">
		<ul class="menu clearfix">
			<li>
				<a href="index.html">
					<i class="icon ico-01"></i>
					<span>主页</span>
				</a>
			</li>
			<li>
				<a href="login.html" id="authentication">
					<i class="icon ico-02 active"></i>
					<span>认证上网</span>
				</a>
			</li>
			<li>
				<a href="social.html">
					<i class="icon ico-03"></i>
					<span>局域社交</span>
				</a>
			</li>
		</ul>
	</footer>	
	<script>
		function xmlverify(Type){  //获取验证码
			var Phone = $("input[name=phoneNum]").val();
		    
			var encrypt = new JSEncrypt();
	  	  	var PublicKeyString = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFdcf9rnBI5wKkCpJ8yaRviqbXH9cNK/n0foh0s8VLuv+JEvjMESKbE5gYj4FGuIGeEtmTpcchHcI7Z8MTibHHI78CNvy0WsSDyIDMPm+ts/xaeOsiqqAYBYTweGyVrMWKOg6CR0xg4SbtIJ9OGIroclHBjcHZTjsLGm4UHkVsbwIDAQAB";
	      	encrypt.setPublicKey(PublicKeyString);
	      
	      	var strPhone    = encrypt.encrypt(Phone);
	      	var strHexPhone = cryptico.b64to16(strPhone);
	      
	      	var strType    = encrypt.encrypt("2");  //测试时传2 ，已注册也可以反复发送短信 或拨打语音电话
	      	var strHexType = cryptico.b64to16(strType);
	      	var strVer     = "1";
	      	var isVoice    = "1";
	      
	      	var xmlhttp = new XMLHttpRequest();
				 
			var URL="http://113.107.148.182:9080/token/Sendcode";        //调用卡拉威视接口
			xmlhttp.open("POST",URL, false); 
				
			xmlhttp.setRequestHeader ("Content-Type","application/x-www-form-urlencoded"); 	
			if(Type == 1){
			    xmlhttp.send("phone=" + strHexPhone + "&type="+ strHexType +"&ver="+ strVer); 
			}else if(Type == 2){
			    xmlhttp.send("phone=" + strHexPhone + "&type="+ strHexType  + "&isVoice=" + isVoice +"&ver="+ strVer);
			}
			
			var returndate = xmlhttp.responseText;
			var jsonobj=eval('('+returndate+')');  
			if (jsonobj.Response.resultCode == "0"){
			    alert(jsonobj.Response.resultDesc);
			}
		}

		function xmlsubmit() {
			var Phone      = $("input[name=phoneNum]").val();
		    var checkCode  = $("input[name=verifyCode]").val();
		    var Pwd        = $("input[name=password]").val();
		    var confirmPwd = $("input[name=confirmPassword]").val();
		    //var reGWnumber = $("input[name=referrer]").val();
			
			if(Pwd!=confirmPwd){
				$("#pw-uniformity").show();
				return false;
			}
			var encrypt = new JSEncrypt();
	  	  	var PublicKeyString = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFdcf9rnBI5wKkCpJ8yaRviqbXH9cNK/n0foh0s8VLuv+JEvjMESKbE5gYj4FGuIGeEtmTpcchHcI7Z8MTibHHI78CNvy0WsSDyIDMPm+ts/xaeOsiqqAYBYTweGyVrMWKOg6CR0xg4SbtIJ9OGIroclHBjcHZTjsLGm4UHkVsbwIDAQAB";
	      	encrypt.setPublicKey(PublicKeyString);
	      
	      	var strPhone    = encrypt.encrypt(Phone);
	      	var strHexPhone = cryptico.b64to16(strPhone);
	      
	      	var strPwd      = encrypt.encrypt(Pwd);
	      	var strHexPwd   = cryptico.b64to16(strPwd);
	        
	      	var strCheckCode    = encrypt.encrypt(checkCode);
	      	var strHexCheckCode = cryptico.b64to16(strCheckCode);
	      
	      	//var strReGWnumber = encrypt.encrypt(reGWnumber);
	      	//var strHexReGWnumber = cryptico.b64to16(strReGWnumber);
	      	var strVer     = "1";
	      
	      	var xmlhttp = new XMLHttpRequest();	 
			var URL="http://113.107.148.182:9080/member/CreateUser";  //调用卡拉威视接口
				
			xmlhttp.open("POST",URL, false); 
			xmlhttp.setRequestHeader ("Content-Type","application/x-www-form-urlencoded"); 
			/*if(reGWnumber == ""){
			  	xmlhttp.send("phone=" + strHexPhone + "&pwd="+ strHexPwd + "&checkCode=" + strHexCheckCode + "&ver=" + strVer); 
			}else if(reGWnumber != ""){
			  	xmlhttp.send("phone=" + strHexPhone + "&pwd="+ strHexPwd + "&checkCode=" + strHexCheckCode + "&reGWnumber=" + strHexReGWnumber + "&ver="+ strVer); 
		    }*/
		    
		  xmlhttp.send("phone=" + strHexPhone + "&pwd="+ strHexPwd + "&checkCode=" + strHexCheckCode + "&ver=" + strVer); 
				
			var returndate = xmlhttp.responseText;
			var jsonobj=eval('('+returndate+')');  
			//alert("获取验证码接口返回："+jsonobj.Response.resultCode + "（0 失败，1 成功）");  
			//alert("获取验证码接口返回信息："+jsonobj.Response.resultDesc);
			if (jsonobj.Response.resultCode == "1"){ 	 
				openInternet();     
				//alert("注册成功！");				
			}else{
			  	//alert(jsonobj.Response.resultDesc);
			  	//window.location.href = "./error2.html";
			  	$('.ca-wrap').append('<div class="mask"><div class="tooltip-box"><i class="close"></i><p>'+jsonobj.Response.resultDesc+'</p></div></div>');
			  	$(".tooltip-box .close").click(function(){
					$(this).parent().parent().hide();
				})
			}
			
		}
	  	function openInternet(){  //打开外网访问功能
	        console.log("openInternet");
	        $.ajax({
	            url: "http://192.168.7.7:2060/wifidog/auth?token=ASDfghJKLqwerTYUIOP",
	            type: 'get',
	            success: function(re) {
	                console.log(re);
	            },
	            complete: function(XHR) {
	                //window.location.href = "./success.html";
	                $('.ca-wrap').append('<div class="mask"><div class="tooltip-box"><i class="close"></i><p class="narrow">恭喜您，注册成功！</p><a href="login.html" class="button">马上去认证</a></div></div>');
	                $(".tooltip-box .close").click(function(){
						$(this).parent().parent().hide();
					})
	            }
	        });
	  	}
	</script>
</body>
</html>